package com.naiterui.ehp.bs.patient.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.context.ResourceHolder;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.security.SettingConfig;
import com.naiterui.ehp.bp.support.utils.IpUtil;
import com.naiterui.ehp.bp.utils.payment.bo.UnifiedOrderResultBO;
import com.naiterui.ehp.bs.patient.service.IApSelfInspectService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

/**
 * @author luao
 * @date 2022/4/21 10:38 AM
 **/
@Api(tags = {SwaggerTag.PATIENT + SwaggerTag.SELF_INSPECT})
@RestController
@RequestMapping("ap/self/inspect")
@RequiredArgsConstructor
public class ApSelfInspectController {

    private final IApSelfInspectService apSelfInspectService;

    @ApiOperation(value = "微信支付自检")
    @GetMapping("/wx/pay")
    public UnifiedOrderResultBO pay(Long patientId, HttpServletRequest request) throws BusinessException {
        if (null == patientId) {
            patientId = (Long)ResourceHolder.getResource(SettingConfig.PATIENT_ID);
        }
        String ip = IpUtil.getIp(request);
        return apSelfInspectService.pay(patientId, ip);
    }

    @ApiOperation(value = "微信支付退款")
    @GetMapping("/wx/refund")
    public void refund(Long patientId) throws BusinessException {
        if (null == patientId) {
            patientId = (Long)ResourceHolder.getResource(SettingConfig.PATIENT_ID);
        }
        apSelfInspectService.refund(patientId);
    }
}
